// Fill out your copyright notice in the Description page of Project Settings.


#include "SElectAssetsView.h"
#include "SlateOptMacros.h"
#include "Widgets/SBoxPanel.h"
#include "SElectAssetRow.h"

#define LOCTEXT_NAMESPACE "SElectAssetsView"

BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SElectAssetsView::Construct(const FArguments& InArgs)
{
	ChildSlot
	[
		SNew(SVerticalBox)
		+ SVerticalBox::Slot()
		.AutoHeight()
		.MaxHeight(256.0f)
		[
			SAssignNew(AssetViewTree, SListView<TSharedPtr<FName>>)
			.HeaderRow(
				SNew(SHeaderRow)
				.Visibility(EVisibility::Collapsed)

				+ SHeaderRow::Column("AssetName")
				.DefaultLabel(LOCTEXT("AssetNameColumnHeader", "Asset"))
				.FillWidth(1.0f)
			)
		.ItemHeight(16.0f)
		.ListItemsSource(&AssetList)
		.OnGenerateRow(this, &SElectAssetsView::HandleAssetViewGenerateRow)
		.SelectionMode(ESelectionMode::None)
		]
	];
}


END_SLATE_FUNCTION_BUILD_OPTIMIZATION

TSharedRef<ITableRow> SElectAssetsView::HandleAssetViewGenerateRow(TSharedPtr<FName> AssetName, const TSharedRef<STableViewBase>& OwnerTable)
{
	return SNew(SElectAssetRow, this)
		.AssetName(AssetName)
		.OwnerTableView(OwnerTable);
}

void SElectAssetsView::SelectAssetsChange(TArray<FName> SelelctAssets)
{
	AssetList.Reset();

	for (auto SelelctAsset : SelelctAssets)
		AssetList.Add(MakeShareable(new FName(SelelctAsset)));

	AssetViewTree->RequestListRefresh();
}


#undef LOCTEXT_NAMESPACE
